Add new versioned request for server update.
authorrobertl <robertl>
Thu, 6 Aug 2009 01:54:06 +0000 (01:54 +0000)
committerrobertl <robertl>
Thu, 6 Aug 2009 01:54:06 +0000 (01:54 +0000)
gui/upgrade.cpp
gui/upgrade.h

index b8efbdfbb018d8b4c0512c62d9c6d148f89353da..f2bcdaa1b8fc85f7cf0733fd14e0b280f465edb0 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: upgrade.cpp,v 1.3 2009/08/03 05:16:23 robertl Exp $
+// $Id: upgrade.cpp,v 1.4 2009/08/06 01:54:06 robertl Exp $
 /*
     Copyright (C) 2009  Robert Lipe, robertlipe@gpsbabel.org
 
@@ -23,9 +23,9 @@
 #include "upgrade.h"
 
 #include <QHttp>
-//#include <QHttpRequestHeader>
 #include <QMessageBox>
 #include <QDomDocument>
+#include <QSysInfo>
 
 static const bool testing = true;
 // static const bool testing = false;
@@ -52,8 +52,20 @@ UpgradeCheck::~UpgradeCheck()
   }
 }
 
-void UpgradeCheck::changeEvent(QEvent *)
+// See http://doc.trolltech.com/4.5/qsysinfo.html to interpret results
+QString UpgradeCheck::UpgradeCheck::getOsName(void)
 {
+       // Do not translate these strings.
+#if defined (Q_OS_LINUX)
+               return "Linux";
+#elif defined (Q_OS_MAC)
+       return QString("Mac %1").arg(QSysInfo::MacintoshVersion);
+#elif defined (Q_OS_WIN)
+       return QString("Windows %1").arg(QSysInfo::WindowsVersion);
+#elif
+       return "Unknown"'
+#endif
+       
 }
 
 UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentVersion,
@@ -69,6 +81,7 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentV
     // Not time to check yet.
     return UpgradeCheck::updateUnknown;
   }
+       
   http = new QHttp;
   
   connect(http, SIGNAL(requestFinished(int, bool)),
@@ -77,15 +90,16 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentV
           this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
   
   QHttpRequestHeader header("POST", "/upgrade_check.html");
-       header.setValue("Host",  "www.gpsbabel.org");
-               header.setContentType("application/x-www-form-urlencoded");
- QString args = "current_version=" + currentVersion;
-   args += "&installation=" + installationUuid;        header.setValue("Host", "www.gpsbabel.org");
-       
+  header.setValue("Host",  "www.gpsbabel.org");
+  header.setContentType("application/x-www-form-urlencoded");
+  header.setValue("Host", "www.gpsbabel.org");
+
+  QString args = "current_version=" + currentVersion;
+  args += "&installation=" + installationUuid; 
+       args += "&os=" + getOsName();   
+
   http->setHost("www.gpsbabel.org");
-//     http->request(header);
-       http->request(header, args.toUtf8());
-//  httpRequestId = http->get("/upgrade_check.html");
+       httpRequestId = http->request(header, args.toUtf8());
 
   return UpgradeCheck::updateUnknown;
 }
@@ -149,16 +163,18 @@ void UpgradeCheck::httpRequestFinished(int requestId, bool error)
       response = tr("<center><b>A new version of GPSBabel is available</b><br>"
                    "Your version is %1 <br>"
                    "The latest version is %2</center>")
-       .arg(currentVersion)
-       .arg(updateVersion);
+               .arg(currentVersion)
+               .arg(updateVersion);
 
       break;  
     }
   }
+       
   if (response.length()) {
     QMessageBox::information(0, tr("Upgrade"), response);
     upgradeWarningTime = QDateTime(QDateTime::currentDateTime());
   }
+       
   delete http;
   http = 0;
 }
index 914e305a7f72f90efa45d33dbf3b874fc465a3dd..89753d79402876f5b2d663de8c61466904ede7af 100644 (file)
@@ -48,7 +48,6 @@ public:
   }
 
 protected:
-  void changeEvent(QEvent *e);
 
  private:
   QString currentVersion;
@@ -58,6 +57,7 @@ protected:
   bool httpRequestAborted;
   QString latestVersion;
   QDateTime upgradeWarningTime;  // invalid time if this object never issued.
+  QString getOsName(void);
 
 private slots:
   void httpRequestFinished(int requestId, bool error);